# waa.py - windows application automation, vp

import glob
import win32api
import win32com.client

# sleep (seconds)
sleep = lambda x: win32api.Sleep(x*1000)

# before running this, have to setup custom keyboard shortcuts mapping of oo:

## oo/View/Toolbars/Customize/Keyboard .... F3 = ExportAllData 
## (inside macro disable -by commenting out- MsgBox on end of macro ... MsgBox("All sheets were exported."))

## oo/View/Toolbars/Customize/Keyboard .... Shift+F3 = Application/Exit

for f in glob.glob('*.xls'):

    print f
    shell = win32com.client.Dispatch("WScript.Shell")
    shell.Run("scalc %s"%f)
    sleep(5)
    shell.AppActivate("Calc")

    # macro :: replaceHex0A
    #shell.SendKeys("{F11}")
    #sleep(6)
    # confirm :: "Nothing found" dialogs
    #shell.SendKeys("{ENTER}")
    #sleep(1)
  
    # run macro :: ExportAllData
    shell.SendKeys("{F3}")
    sleep(6)

    # close scalc
    shell.SendKeys("+{F3}")

